﻿using System;
using System.Collections.Generic;
using Aragorn.SOA.ORM.Lambda.Adapter;
using Aragorn.SOA.ORM.Lambda.Builder;
using Aragorn.SOA.ORM.Lambda.Resolver;
using Aragorn.SOA.ORM.Lambda.ValueObjects;
using Aragorn.SOA.ORM.Lambda.Adapter;
using Aragorn.SOA.ORM.Lambda.Builder;
using Aragorn.SOA.ORM.Lambda.Resolver;

namespace  Aragorn.SOA.ORM.Lambda
{
    public abstract class SqlLamBase
    {
        internal static ISqlAdapter _defaultAdapter;

        internal SqlQueryBuilder _builder;

        internal LambdaResolver _resolver;

        public string DeleteString
        {
            get
            {
                return this._builder.DeleteString;
            }
        }

        public IDictionary<string, object> QueryParameters
        {
            get
            {
                return this._builder.Parameters;
            }
        }

        public string QueryString
        {
            get
            {
                return this._builder.QueryString;
            }
        }

        public string[] SplitColumns
        {
            get
            {
                return this._builder.SplitColumns.ToArray();
            }
        }

        public SqlQueryBuilder SqlBuilder
        {
            get
            {
                return this._builder;
            }
        }

        static SqlLamBase()
        {
            SqlLamBase._defaultAdapter = new SqlServer2008Adapter();
        }

        protected SqlLamBase()
        {
        }

        private static ISqlAdapter GetAdapterInstance(SqlAdapter adapter)
        {
            switch (adapter)
            {
                case SqlAdapter.SqlServer2008:
                    {
                        return new SqlServer2008Adapter();
                    }
                case SqlAdapter.SqlServer2012:
                    {
                        return new SqlServer2012Adapter();
                    }
            }
            throw new ArgumentException("The specified Sql Adapter was not recognized");
        }

        public string QueryStringPage(int pageSize, int? pageNumber = null)
        {
            return this._builder.QueryStringPage(pageSize, pageNumber);
        }

        public static void SetAdapter(SqlAdapter adapter)
        {
            SqlLamBase._defaultAdapter = SqlLamBase.GetAdapterInstance(adapter);
        }
    }
}